package cz.fit.dpo.task1;

import java.util.ArrayList;
import java.util.List;

/**
 * class for representing rooms in this game
 */
public class Room implements IHaveItem {

	/**
	 * list of items owned
	 */
	private List<Item> ownedItems;

	/**
	 * list of neighbouring rooms
	 */
	private List<Room> neighbouringRooms;

	/**
	 * name of this room
	 */
	private String name;

	/**
	 * constructs this room with given name
	 */
	public Room (String name) {
		setName (name);
		ownedItems = new ArrayList<Item>();
		neighbouringRooms = new ArrayList<Room>();
	}
	
	/**
	 * is this room opened for the player?
	 */
	public boolean isOpen (Player player) {
		// here can be any desired logic
		return true;
	}
	
	/**
	 * can specific item be added to this room?
	 */
	public boolean canAddItem (Item toBeDroppedItem) {
		// here can be any desired logic
		return true;
	}
	
	/**
	 * can specific item be removed from this room?
	 */
	public boolean canRemoveItem (Item toBeLiftedItem) {
		return toBeLiftedItem.isMovable();
	}

	/**
	 * is the specific room neighbour of this room?
	 */
	public boolean isNeighbour ( Room room ) {
		for ( Room aRoom : neighbouringRooms ) {
			if ( room == aRoom ) {
				return true;
			}
		}
		return false;
	}
	
	/**
	 * gets items in this room
	 */
	public List<Item> getOwnedItems() {
		return ownedItems;
	}

	/**
	 * add item to this room
	 */
	public void addOwnedItem(Item newItem) {
		this.ownedItems.add(newItem);
		newItem.setOwner(this);
	}

	/**
	 * does this rooms owns specific item?
	 */
	public boolean owns (Item item) {
		return ownedItems.contains(item);
	}

	/**
	 * removes item from this room
	 */
	public void removeOwnedItem(Item lostItem) {
		this.ownedItems.remove(lostItem);
	}

	/**
	 * gets neighbouring rooms of this room
	 */
	public List<Room> getNeighbouringRooms() {
		return neighbouringRooms;
	}

	/**
	 * add doors to this room
	 */
	public void addNeighbouringRoom(Room neighbouringRoom) {
		this.neighbouringRooms.add (neighbouringRoom);
	}

	/**
	 * gets the name of this room
	 */
	public String getName() {
		return name;
	}

	/**
	 * sets the name of this room
	 */
	private void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return name;
	}

}
